<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form divClass" v-if="headerShow" style="margin-top: 15px">
        <div>
          <a-form size="small" :model="pageData" layout="inline" label-col-flex="80px">
            <CorporateSectorCascader
              :configCascader="configCascader2"
              @changeCascader="firmChange"
            />
            <a-form-item label="仓库" required label-col-flex="80px">
              <a-select
                popup-container="html"
                class="bacClass"
                :style="{ width: '189px' }"
                v-model="pageData.warehouseId"
                allow-clear
              >
                <a-option v-for="item in fhWhList" :value="item.id">
                  {{ item.warehouseName }}
                </a-option>
              </a-select>
            </a-form-item>
            <a-form-item label="原料编号" label-col-flex="80px">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageData.yuanliaobianhao"
                @press-enter="huiche"
              />
            </a-form-item>

            <a-form-item field="value2" label="原料名称" label-col-flex="80px">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageData.yuanliaomingcheng"
                @press-enter="huiche"
              />
            </a-form-item>

            <a-form-item field="value3" label="批次" label-col-flex="80px">
              <!-- <a-cascader class="bacClass" :style="{ width: '200px' }"  v-model="pageData.pici" :options="pageData.picilist" @focus="focusSel7"
                             @change="changeFrim"  allow-clear  />  -->
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageData.pici"
                @press-enter="huiche"
              />
            </a-form-item>

            <a-form-item field="value2" label="纱牌" label-col-flex="80px">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageData.yarnBrand"
                @press-enter="huiche"
              />
            </a-form-item>
            <a-form-item field="level" label="等级" label-col-flex="80px">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageData.level"
                @press-enter="huiche"
              />
            </a-form-item>
            <!-- <a-form-item field="value2" label="月份">
              <a-month-picker
                :style="{ width: '200px' }"
                @press-enter="huiche"
                class="bacClass"
                v-model="pageData.jianyanriqi"
              />
            </a-form-item> -->
          </a-form>
        </div>
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up
            v-if="headerShow"
            @click="headerShow = false"
            :strokeWidth="2"
            :size="18"
          />
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18" />
        </a-divider>
      </div>
      <div class="my-tool-bar">
        <Toolbar
          class="gesture"
          :items="pageData.btnList"
          @select="selectHandler"
          @export="exportsSelectedRows"
          @fhzy="fhzy"
          @exportAll="exportsAll"
          @exportToday="exportsToday"
        >
        </Toolbar>
      </div>
    </template>
    <template #pageTabel>
      <!--
                            表格插件
                        -->
      <a-spin
        :loading="pageData.pageLoading"
        tip="加载中"
        dot
        style="height: 100%; width: 100%; z-index: 999"
      >
        <AgGridVuesCopys
          :rowHeight="33"
          :headerHeight="33"
          rowSelection="multiple"
          @grid-ready="gridReady"
          style="height: 100%"
          :defaultColDef="defaultColDef"
          class="ag-theme-alpine"
          :rowData="table.dataList"
          :columnDefs="tc1"
          :localeText="localeText1"
          :suppressCopyRowsToClipboard="true"
          @columnResized="onColumnResized"
          @columnMoved="onColumnMoved"
          @columnVisible="onColumnVisible"
          @FilterChanged="FilterChangeds"
        ></AgGridVuesCopys>
      </a-spin>
    </template>
    <paginationCopys
      :page-size-options="pagingList1"
      :total="total"
      :page-size="size"
      show-total
      show-jumper
      show-page-size
      :current="page"
      @change="PageSize"
      @page-size-change="change1"
      style="justify-content: center"
    />
    <a-drawer
      style="z-index: 999"
      ok-text="保存"
      cancel-text="关闭"
      :drawer-style="{ zIndex: 9999 }"
      :mask-closable="false"
      :width="400"
      :ok-loading="pageData.pageLoading"
      :visible="pageData.showAdd"
      unmountOnClose
      @ok="sideOk"
      @cancel="pageData.showAdd = false"
    >
      <template #title>
        {{ pageData.sideTitle }}
      </template>
      <div>
        <a-form ref="formRef" layout="horizontal" :model="dataForm">
          <a-form-item
            label-col-flex="80px"
            label="编号"
            field="brandCode"
            :rules="[{ validator: isChiese }, { required: true, message: '编号必填' }]"
            :validate-trigger="['change', 'blur']"
          >
            <a-input
              class="bacClass"
              placeholder=""
              v-model="dataForm.brandCode"
              @blur="inputBlur"
            />
          </a-form-item>
          <a-form-item
            label-col-flex="80px"
            label="品牌名称"
            field="brandName"
            :rules="[{ required: true, message: '品牌名称必填' }]"
            :validate-trigger="['change', 'blur']"
          >
            <a-input class="bacClass" placeholder="" v-model="dataForm.brandName" />
          </a-form-item>
          <a-form-item
            label-col-flex="80px"
            label="布类类型"
            field="clothClass"
            :rules="[{ required: true, message: '布类类型必填' }]"
            :validate-trigger="['change', 'blur']"
          >
            <a-select
              class="bacClass"
              :loading="loading"
              placeholder=""
              @search="handleSearch1"
              v-model="dataForm.clothClass"
              :filter-option="false"
              allow-search
              allow-clear
              @focus="focusSel1"
            >
              <a-option v-for="item in pageData.typeList" :value="item">{{ item }}</a-option>
            </a-select>
          </a-form-item>
          <a-form-item label-col-flex="80px" label="备注" field="remark">
            <!-- <a-input v-model="dataForm.remark" /> -->
            <a-textarea
              class="bacClass"
              v-model="dataForm.remark"
              :max-length="400"
              allow-clear
              show-word-limit
            />
          </a-form-item>
        </a-form>
      </div>
    </a-drawer>
  </pageTabelLayout>
</template>

<script lang="ts">
  import { post, get } from '@/api/http'
  import {
    useTable,
    useRowKey,
    useTableColumn,
    usePagination,
    useRowSelection,
  } from '@/hooks/table'
  import emitter from '@/hooks/useEventBus'
  import { ref, reactive, onMounted, toRefs } from 'vue'
  import Toolbar from '@/components/Toolbar.vue'
  import { Button, Form, Message, Modal } from '@arco-design/web-vue'
  import { FormInstance } from '@arco-design/web-vue/es/form'
  import { baseURL } from '../../../api/axios.config'
  import axios from 'axios'
  import filedownload from 'js-file-download'
  import usePermission from '@/store/modules/permission'
  import PageTabelLayout from '@/components/pageTabelLayout.vue'
  import MyTable from '@/components/MyTable'
  import ButtonRenderer from '@/components/TableCellRenderer/ButtonRenderer'
  import { template } from 'lodash'
  import { setupGlobalComponent } from '@/layouts'
  import { localeText } from '@/api/aggridZw'
  import { pagingList } from '@/api/paging'
  import { slicing } from '@/utils/caseFrimAndSecRig'
  // 引入
  
  import { stringify } from 'qs'
  import CorporateSectorCascader from '@/components/corporateSectorCascader/inde.vue'
  //封装好的记忆表头的方法
  import { saveOrUpdateGridState as saveOrUpdateGridState01 } from '@/hooks/useGridState'
  import WHService from '@/service/wh'
  import setTableTotalRow from '@/utils/setTableTotalRow.ts'
  interface BrandInfo {
    id: any
    brandCode: string
    brandName: string
    clothClass: string
    remark: string
    deleteState: number | string
    createName: string
    createTime: string
    updateName: string
    updateTime: string
  }

  export default {
    name: 'Rawmaterialstorage',

    setup(props: any, { emit }) {
      const total = ref(0)
      const page = ref(1)
      const size = ref(10)
      function PageSize(val: any) {
        page.value = val
        doRefresh()
      }
      function change1(val: any) {
        size.value = val
        doRefresh()
      }
      const headerShow = ref<boolean>(true)
      const whService = new WHService()
      const fhWhList: any = whService.whList
      const configCascader2 = ref<{}>({
        corporateWidth: '160px', //公司宽度
        sectorWidth: '180px', //部门宽度
        corporateRquired: true, //公司是否必填
        sectorRquired: false, //部门是否必填
        size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
        corporateName: '选择工厂', //公司label
        sectorName: '选择部门', //部门label
        cascaderShow: 'sector', //配置部门不显示
        corporateNameLabelWidth: '80px',
      })
      const toFixedNum = (num: number | string) => {
        if (num === '' || num === null || num === undefined) {
          num = ''
        } else {
          if (typeof num == 'string') {
            num = parseFloat(Number(num).toFixed(2))
          }
        }

        return num
      }
      const firmChange = (data: any) => {
        // const { corporateId, sectorId, sectorLabel, corporateLabel } = data
        // pageData.dropDownData = corporateId
        const { corporateId, sectorId, sectorLabel, corporateLabel } = data
        pageData.warehouseId = ''
        pageData.firmId = corporateId
        whService.getWarhouseListByFirmId(corporateId, '原纱仓')
      }
      function doRefresh() {
        var obj = { page: page.value, size: size.value }
        if (pageData.firmId == '' || pageData.firmId == null) {
          Message.error('工厂必填！')
          return
        }
        if (pageData.warehouseId == '' || pageData.firmId == null) {
          Message.error('仓库必填！')
          return
        }
        if (pageData.kehumingcheng != '') {
          obj['customName'] = pageData.kehumingcheng
        }
        if (pageData.yuanliaobianhao != '') {
          obj['weaveCode'] = pageData.yuanliaobianhao
        }
        if (pageData.jihuaCode != '') {
          obj['planOrderCode'] = pageData.jihuaCode
        }
        if (pageData.dingdan != '') {
          obj['weavDeliveryDate'] = pageData.dingdan
        }
        if (pageData.kaidan != '') {
          obj['planDate'] = pageData.kaidan
        }
        if (pageData.yarnBrand != '') {
          obj['yarnBrand'] = pageData.yarnBrand
        }
        if (pageData.level != '') {
          obj['level'] = pageData.level
        }

        pageData.pageLoading = true
        post({
          url: '/wms/yarnStockRecord/getPageYarnStockRecord',
          data: {
            firmId: pageData.firmId,
            warehouseId: pageData.warehouseId,
            page: page.value,
            size: size.value,
            // recordDate: pageData.jianyanriqi,//记录日期
            customName: pageData.kehumingcheng, //客户
            yarnCode: pageData.yuanliaobianhao, //原料编号
            yarnName: pageData.yuanliaomingcheng, //纱线名称
            yarnBrand: pageData.yarnBrand, //纱牌
            productionBatch: pageData.pici, //生产批号-纱批
            level: pageData.level, //等级
          },
        })
          .then(async ({ data, code }: any) => {
            if (code === 200) {
              table.handleSuccess(data.list)
              sessionStorage.setItem('cmn', JSON.stringify(data))
              // 查询方法改
              gridOption.value.setFilterModel(null)
              gridOption.value.setRowData(data.list)
              setTableTotalRow(gridOption, data.list, [
                'pieceNumberBalanceL',
                'bulkNumberBalanceL',
                'bulkWeightBalanceL',
                'weightTotalBalanceL',
                'pieceNumberIn',
                'bulkNumberIn',
                'bulkWeightIn',
                'weightTotalIn',
                'pieceNumberOutClaim',
                'bulkNumberOutClaim',
                'bulkWeightOutClaim',
                'weightTotalOutClaim',
                'pieceNumberOutSource',
                'bulkNumberOutSource',
                'bulkWeightOutSource',
                'weightTotalOutSource',
                'pieceNumberOutOther',
                'bulkNumberOutOther',
                'bulkWeightOutOther',
                'weightTotalOutOther',
                'pieceNumberBalanceN',
                'bulkNumberBalanceN',
                'bulkWeightBalanceN',
                'weightTotalBalanceN',
              ])
              total.value = data.total
            }
          })
          .catch(console.log)
          .finally(() => {
            pageData.pageLoading = false
          })
      }

      const { selectedRowKeys, onSelectionChange } = useRowSelection()
      const pagination = usePagination(doRefresh)
      const table = useTable()
      const rowKey = useRowKey('id')
      const tc1 = [
        {
          headerCheckboxSelection: true,
          checkboxSelection: true,
          width: 50,
          showDisabledCheckboxes: false,
          pinned: 'left',
          autoHeaderHeight: true,
        },
        {
          headerName: '公司',
          field: 'firm',
          dataIndex: 'firm',
          width: 150,
        },

        {
          headerName: '客户名称',
          field: 'customName',
          dataIndex: 'customName',
          width: 150,
        },
        {
          headerName: '原料编号',
          field: 'yarnCode',
          dataIndex: 'yarnCode',
          width: 150,
        },

        {
          headerName: '纱线名称',
          field: 'yarnName',
          dataIndex: 'yarnName',
          width: 200,
        },
        {
          headerName: '纱牌',
          field: 'yarnBrand',
          dataIndex: 'yarnBrand',
          width: 150,
        },
        {
          headerName: '生产批号-纱批',
          field: 'productionBatch',
          dataIndex: 'productionBatch',
          width: 200,
        },

        {
          headerName: '等级',
          field: 'level',
          dataIndex: 'level',
          width: 200,
        },
        {
          headerName: '色号',
          field: 'colorCode',
          dataIndex: 'colorCode',
          width: 200,
        },
        {
          headerName: '色称',
          field: 'colorName',
          dataIndex: 'colorName',
          width: 200,
        },
        {
          headerName: '单位',
          field: 'unit',
          dataIndex: 'unit',
          width: 200,
        },
        {
          headerName: '整件/件重',
          field: 'pieceWeight',
          dataIndex: 'pieceWeight',
          width: 200,
          valueFormatter: (params: any) => {
            return toFixedNum(params.value)
          },
        },

        {
          headerName: '上期结存',
          children: [
            {
              headerName: '整件/件数',
              headerClass: 'my-header-class',
              width: 200,
              field: 'pieceNumberBalanceL',
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '整件/个数',
              width: 200,
              field: 'pieceCountBalanceL',
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '散件/件数',
              field: 'bulkNumberBalanceL',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '散件/散重',
              field: 'bulkWeightBalanceL',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '散件/个数',
              field: 'bulkCountBalanceL',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '总数量',
              field: 'weightTotalBalanceL',
              headerClass: 'blue-header',
              cellClass: 'bold-cell',
              cellStyle: {
                color: 'blue',
              },
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
          ],
        },
        {
          headerName: '入仓',
          children: [
            {
              headerName: '整件/件数',
              field: 'pieceNumberIn',
              dataIndex: 'pieceNumberIn',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '整件/个数',
              field: 'pieceCountIn',
              dataIndex: 'pieceCountIn',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '散件/件数',
              field: 'bulkNumberIn',
              dataIndex: 'bulkNumberIn',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '散件/散重',
              field: 'bulkWeightIn',
              dataIndex: 'bulkWeightIn',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '散件/个数',
              field: 'bulkCountIn',
              dataIndex: 'bulkCountIn',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '总数量',
              field: 'weightTotalIn',
              dataIndex: 'weightTotalIn',
              headerClass: 'blue-header',
              cellClass: 'bold-cell',
              cellStyle: {
                color: 'blue',
              },
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
          ],
        },
        {
          headerName: '出仓领料',
          children: [
            {
              headerName: '整件/件数',
              field: 'pieceNumberOutClaim',
              dataIndex: 'pieceNumberOutClaim',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '整件/个数',
              field: 'pieceCountOutClaim',
              dataIndex: 'pieceCountOutClaim',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '散件/件数',
              field: 'bulkNumberOutClaim',
              dataIndex: 'bulkNumberOutClaim',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '散件/散重',
              field: 'bulkWeightOutClaim',
              dataIndex: 'bulkWeightOutClaim',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '散件/个数',
              field: 'bulkCountOutClaim',
              dataIndex: 'bulkCountOutClaim',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '总数量',
              field: 'weightTotalOutClaim',
              dataIndex: 'weightTotalOutClaim',
              headerClass: 'blue-header',
              cellClass: 'bold-cell',
              cellStyle: {
                color: 'blue',
              },
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
          ],
        },
        {
          headerName: '出仓委外',
          children: [
            {
              headerName: '整件/件数',
              field: 'pieceNumberOutSource',
              dataIndex: 'pieceNumberOutSource',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '整件/个数',
              field: 'pieceCountOutSource',
              dataIndex: 'pieceCountOutSource',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },

            {
              headerName: '散件/件数',
              field: 'bulkNumberOutSource',
              dataIndex: 'bulkNumberOutSource',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '散件/散重',
              field: 'bulkWeightOutSource',
              dataIndex: 'bulkWeightOutSource',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '散件/个数',
              field: 'bulkCountOutSource',
              dataIndex: 'bulkCountOutSource',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '总数量',
              field: 'weightTotalOutSource',
              dataIndex: 'weightTotalOutSource',
              headerClass: 'blue-header',
              cellClass: 'bold-cell',
              cellStyle: {
                color: 'blue',
              },
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
          ],
        },
        {
          headerName: '出仓其他',
          children: [
            {
              headerName: '整件/件数',
              field: 'pieceNumberOutOther',
              dataIndex: 'pieceNumberOutOther',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '整件/个数',
              field: 'pieceCountOutOther',
              dataIndex: 'pieceCountOutOther',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '散件/件数',
              field: 'bulkNumberOutOther',
              dataIndex: 'bulkNumberOutOther',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '散件/散重',
              field: 'bulkWeightOutOther',
              dataIndex: 'bulkWeightOutOther',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '散件/个数',
              field: 'bulkCountOutOther',
              dataIndex: 'bulkCountOutOther',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '总数量',
              field: 'weightTotalOutOther',
              dataIndex: 'weightTotalOutOther',
              headerClass: 'blue-header',
              cellClass: 'bold-cell',
              cellStyle: {
                color: 'blue',
              },
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
          ],
        },
        {
          headerName: '本期结存',
          children: [
            {
              headerName: '整件/件数',
              field: 'pieceNumberBalanceN',
              dataIndex: 'pieceNumberBalanceN',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '整件/个数',
              field: 'pieceCountBalanceN',
              dataIndex: 'pieceCountBalanceN',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '散件/件数',
              field: 'bulkNumberBalanceN',
              dataIndex: 'bulkNumberBalanceN',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '散件/散重',
              field: 'bulkWeightBalanceN',
              dataIndex: 'bulkWeightBalanceN',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '散件/个数',
              field: 'bulkCountBalanceN',
              dataIndex: 'bulkCountBalanceN',
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
            {
              headerName: '总数量',
              field: 'weightTotalBalanceN',
              dataIndex: 'weightTotalBalanceN',
              headerClass: 'green-header',
              cellClass: 'bold-cell',
              cellStyle: {
                color: 'green',
              },
              width: 200,
              valueFormatter: (params: any) => {
                return toFixedNum(params.value)
              },
            },
          ],
        },
      ]
      // const tableColumns = useTableColumn([
      //   {
      //     title: '公司',
      //     key: 'firm',
      //     dataIndex: 'firm',
      //     width: 150,
      //   },

      //   {
      //     title: '客户名称',
      //     key: 'customName',
      //     dataIndex: 'customName',
      //     width: 150,
      //   },
      //   {
      //     title: '原料编号',
      //     key: 'yarnCode',
      //     dataIndex: 'yarnCode',
      //     width: 150,
      //   },

      //   {
      //     title: '纱线名称',
      //     key: 'yarnName',
      //     dataIndex: 'yarnName',
      //     width: 200,
      //   },
      //   {
      //     title: '纱牌',
      //     key: 'yarnBrand',
      //     dataIndex: 'yarnBrand',
      //     width: 150,
      //   },
      //   {
      //     title: '生产批号-纱批',
      //     key: 'productionBatch',
      //     dataIndex: 'productionBatch',
      //     width: 200,
      //   },

      //   {
      //     title: '等级',
      //     key: 'level',
      //     dataIndex: 'level',
      //     width: 200,
      //   },
      //   {
      //     title: '色号',
      //     key: 'colorCode',
      //     dataIndex: 'colorCode',
      //     width: 200,
      //   },
      //   {
      //     title: '色称',
      //     key: 'colorName',
      //     dataIndex: 'colorName',
      //     width: 200,
      //   },
      //   {
      //     title: '单位',
      //     key: 'unit',
      //     dataIndex: 'unit',
      //     width: 200,
      //   },
      //   {
      //     title: '整件/件重',
      //     key: 'pieceWeight',
      //     dataIndex: 'pieceWeight',
      //     width: 200,
      //   },
      //   {
      //     title: '上期结存-整件/件数',
      //     key: 'pieceNumberBalanceL',
      //     dataIndex: 'pieceNumberBalanceL',
      //     width: 200,
      //   },
      //   {
      //     title: '上期结存-整件/个数',
      //     key: 'pieceCountBalanceL',
      //     dataIndex: 'pieceCountBalanceL',
      //     width: 200,
      //   },
      //   {
      //     title: '上期结存-散件/件数',
      //     key: 'bulkNumberBalanceL',
      //     dataIndex: 'bulkNumberBalanceL',
      //     width: 200,
      //   },
      //   {
      //     title: '上期结存-散件/散重',
      //     key: 'bulkWeightBalanceL',
      //     dataIndex: 'bulkWeightBalanceL',
      //     width: 200,
      //   },
      //   {
      //     title: '上期结存-散件/个数',
      //     key: 'bulkCountBalanceL',
      //     dataIndex: 'bulkCountBalanceL',
      //     width: 200,
      //   },
      //   {
      //     title: '上期结存-总数量',
      //     key: 'weightTotalBalanceL',
      //     dataIndex: 'weightTotalBalanceL',
      //     width: 200,
      //   },
      //   {
      //     title: '入仓-整件/件数',
      //     key: 'pieceNumberIn',
      //     dataIndex: 'pieceNumberIn',
      //     width: 200,
      //   },
      //   {
      //     title: '入仓-整件/个数',
      //     key: 'pieceCountIn',
      //     dataIndex: 'pieceCountIn',
      //     width: 200,
      //   },
      //   {
      //     title: '入仓-散件/件数',
      //     key: 'bulkNumberIn',
      //     dataIndex: 'bulkNumberIn',
      //     width: 200,
      //   },
      //   {
      //     title: '入仓-散件/散重',
      //     key: 'bulkWeightIn',
      //     dataIndex: 'bulkWeightIn',
      //     width: 200,
      //   },
      //   {
      //     title: '入仓-散件/个数',
      //     key: 'bulkCountIn',
      //     dataIndex: 'bulkCountIn',
      //     width: 200,
      //   },
      //   {
      //     title: '入仓-总数量',
      //     key: 'weightTotalIn',
      //     dataIndex: 'weightTotalIn',
      //     width: 200,
      //   },
      //   {
      //     title: '出仓-领料-整件/件数',
      //     key: 'pieceNumberOutClaim',
      //     dataIndex: 'pieceNumberOutClaim',
      //     width: 200,
      //   },
      //   {
      //     title: '出仓-领料-整件/个数',
      //     key: 'pieceCountOutClaim',
      //     dataIndex: 'pieceCountOutClaim',
      //     width: 200,
      //   },
      //   {
      //     title: '出仓-领料-散件/件数',
      //     key: 'bulkNumberOutClaim',
      //     dataIndex: 'bulkNumberOutClaim',
      //     width: 200,
      //   },
      //   {
      //     title: '出仓-领料-散件/散重',
      //     key: 'bulkWeightOutClaim',
      //     dataIndex: 'bulkWeightOutClaim',
      //     width: 200,
      //   },
      //   {
      //     title: '出仓-领料-散件/个数',
      //     key: 'bulkCountOutClaim',
      //     dataIndex: 'bulkCountOutClaim',
      //     width: 200,
      //   },
      //   {
      //     title: '出仓-领料-总数量',
      //     key: 'weightTotalOutClaim',
      //     dataIndex: 'weightTotalOutClaim',
      //     width: 200,
      //   },
      //   {
      //     title: '出仓-委外-整件/件数',
      //     key: 'pieceNumberOutSource',
      //     dataIndex: 'pieceNumberOutSource',
      //     width: 200,
      //   },
      //   {
      //     title: '出仓-委外-整件/个数',
      //     key: 'pieceCountOutSource',
      //     dataIndex: 'pieceCountOutSource',
      //     width: 200,
      //   },

      //   {
      //     title: '出仓-委外-散件/件数',
      //     key: 'bulkNumberOutSource',
      //     dataIndex: 'bulkNumberOutSource',
      //     width: 200,
      //   },
      //   {
      //     title: '出仓-委外-散件/散重',
      //     key: 'bulkWeightOutSource',
      //     dataIndex: 'bulkWeightOutSource',
      //     width: 200,
      //   },
      //   {
      //     title: '出仓-委外-散件/个数',
      //     key: 'bulkCountOutSource',
      //     dataIndex: 'bulkCountOutSource',
      //     width: 200,
      //   },
      //   {
      //     title: '出仓-委外-总数量',
      //     key: 'weightTotalOutSource',
      //     dataIndex: 'weightTotalOutSource',
      //     width: 200,
      //   },
      //   {
      //     title: '出仓-其他-整件/件数',
      //     key: 'pieceNumberOutOther',
      //     dataIndex: 'pieceNumberOutOther',
      //     width: 200,
      //   },
      //   {
      //     title: '出仓-其他-整件/个数',
      //     key: 'pieceCountOutOther',
      //     dataIndex: 'pieceCountOutOther',
      //     width: 200,
      //   },
      //   {
      //     title: '出仓-其他-散件/件数',
      //     key: 'bulkNumberOutOther',
      //     dataIndex: 'bulkNumberOutOther',
      //     width: 200,
      //   },
      //   {
      //     title: '出仓-其他-散件/散重',
      //     key: 'bulkWeightOutOther',
      //     dataIndex: 'bulkWeightOutOther',
      //     width: 200,
      //   },
      //   {
      //     title: '出仓-其他-散件/个数',
      //     key: 'bulkCountOutOther',
      //     dataIndex: 'bulkCountOutOther',
      //     width: 200,
      //   },
      //   {
      //     title: '出仓-其他-总数量',
      //     key: 'weightTotalOutOther',
      //     dataIndex: 'weightTotalOutOther',
      //     width: 200,
      //   },
      //   {
      //     title: '本期结存-整件/件数',
      //     key: 'pieceNumberBalanceN',
      //     dataIndex: 'pieceNumberBalanceN',
      //     width: 200,
      //   },
      //   {
      //     title: '本期结存-整件/个数',
      //     key: 'pieceCountBalanceN',
      //     dataIndex: 'pieceCountBalanceN',
      //     width: 200,
      //   },
      //   {
      //     title: '本期结存-散件/件数',
      //     key: 'bulkNumberBalanceN',
      //     dataIndex: 'bulkNumberBalanceN',
      //     width: 200,
      //   },
      //   {
      //     title: '本期结存-散件/散重',
      //     key: 'bulkWeightBalanceN',
      //     dataIndex: 'bulkWeightBalanceN',
      //     width: 200,
      //   },
      //   {
      //     title: '本期结存-散件/个数',
      //     key: 'bulkCountBalanceN',
      //     dataIndex: 'bulkCountBalanceN',
      //     width: 200,
      //   },
      //   {
      //     title: '本期结存-总数量',
      //     key: 'weightTotalBalanceN',
      //     dataIndex: 'weightTotalBalanceN',
      //     width: 200,
      //   },
      //   // {
      //   //     title: "删除状态",
      //   //     key: "deleteState",
      //   //     dataIndex: "deleteState",
      //   //     width: 100,
      //   //     slotName: "deleteState",
      //   //     fixed: 'right'
      //   // },
      // ])

      // let tc: any[] = tableColumns.map((o) => {
      //   let obj = {
      //     headerName: o.title,
      //     field: o.key,
      //     pinned: o['fixed'],
      //     tooltipField: o.key,
      //   }
      //   if (o.key === 'planOrderState') {
      //     obj['resizable'] = false
      //     obj['filter'] = false
      //     obj['sortable'] = false

      //     obj['cellRenderer'] = {
      //       template: `<a-tag color="blue" v-if="a==0&&a!=''">待排产</a-tag>
      //               <a-tag color="blue" v-if="a==1">预排产</a-tag>
      //               <a-tag color="blue" v-if="a==2">已排产</a-tag>
      //               <a-tag color="blue" v-if="a==3">生产中</a-tag>
      //               <a-tag color="blue" v-if="a==4">完成</a-tag>

      //               `,
      //       setup(props: any) {
      //         return {
      //           a: props.params.data.planOrderState,
      //         }
      //       },
      //     }
      //   }

      //   return obj
      // })

      // let a = [
      //   {
      //     showRowGroup: 'hide_def',
      //     headerName: '',
      //     checkboxSelection: true,
      //     headerCheckboxSelection: true,
      //     pinned: 'left',
      //     width: 50,
      //     resizable: false,
      //     filter: false,
      //     sortable: false,
      //     minWidth: 50,
      //     maxWidth: 50,
      //     lockPosition: 'left',
      //   },
      // ]
      // tc = a.concat(tc)
      const pageData = reactive<{
        showAdd: boolean
        sideTitle: string
        dropDownData: any
        nameList: []
        pageLoading: boolean
        typeList: []
        dropDownData1: any
        rHeight: any
        btnList: any[]
        isEdit: boolean
        zhizaocode: any
        hejishuzu: []
        pibubianhao: any
        pibubianhaolist: []
        pibumingcheng: any
        pibumingchenglist: []
        kehumingcheng: any
        kehumingchenglist: any[]
        jianyanriqi: any
        jitaihao: any
        jitaihaolist: []
        firmId2: any
        firmList2: []
        yuangongName: []
        jihuaCode: any
        dingdan: any
        kaidan: any
        yuanliaobianhao: any
        yuanliaobianhaolist: any[]
        yuanliaomingcheng: any
        yuanliaomingchenglist: any[]
        biaoji: any
        pici: any
        picilist: any[]
        yarnBrand: any
        level: any
        firmId: any
        warehouseId: any
      }>({
        nameList: [],
        showAdd: false,
        sideTitle: '新增品牌资料',
        dropDownData: '',
        pageLoading: false,
        typeList: [],
        dropDownData1: '',
        rHeight: 0,
        btnList: [],
        isEdit: false,
        zhizaocode: '',
        hejishuzu: [],
        pibubianhao: '',
        pibubianhaolist: [],
        pibumingcheng: '',
        pibumingchenglist: [],
        kehumingcheng: '',
        kehumingchenglist: [] as any,
        jianyanriqi: '',
        jitaihao: '',
        jitaihaolist: [],
        firmId2: '',
        firmList2: [],
        yuangongName: [],
        jihuaCode: '',
        dingdan: '',
        kaidan: '',
        yuanliaobianhao: '',
        yuanliaobianhaolist: [] as any,
        yuanliaomingcheng: '',
        yuanliaomingchenglist: [] as any,
        biaoji: 0,
        pici: '',
        picilist: [] as any,
        level: '',
        yarnBrand: '',
        firmId: '',
        warehouseId: '',
      })

      interface gcType {
        id: any
        company: any
      }

      //下拉框得到焦点

      //下拉数据

      onMounted(() => {
        // 切换tap到本页面执行的方法
        emitter.on('BrandInfo', () => {
          // selCxAll1({});
          doRefresh()
        })
      })
      let cxbl = ''
      //查询
      const selectHandler = () => {
        pagination.page = 1
        cxbl = pageData.dropDownData
        doRefresh()
      }
      const queryData = reactive({
        clothType: '',
      })
      const addHandler = () => {}
      const dataForm = reactive<BrandInfo>({
        id: null,
        remark: '',
        brandName: '',
        clothClass: '',
        deleteState: '',
        createName: '',
        createTime: '',
        updateName: '',
        updateTime: '',
        brandCode: '',
      })

      // 表格准备事件
      const gridOption = ref()
      const gridReady = (params: any) => {
        gridOption.value = params.api
        colState.value = params.columnApi
      }

      let formRef = ref<FormInstance>()
      const sideOk = () => {
        formRef.value?.validate().then((err) => {
          if (!err) {
            formRef.value?.validate().then((err) => {
              if (!err) {
                pageData.pageLoading = true
                if (pageData.sideTitle === '新增品牌资料') {
                  post({
                    url: 'product/Brand/insert',
                    data: [dataForm],
                  })
                    .then((res: any) => {
                      if (res.code === 200) {
                        formRef.value?.resetFields()
                        pageData.showAdd = false

                        Message.success({
                          content: '新增成功',
                          duration: 5000,
                        })
                      } else {
                        Message.error({
                          content: res.message,
                          duration: 5000,
                        })
                      }
                      doRefresh()
                    })
                    .finally(() => {
                      doRefresh()
                      pageData.pageLoading = false
                    })
                } else {
                  post({
                    url: 'product/Brand/update',
                    data: [dataForm],
                  })
                    .then((res: any) => {
                      if (res.code === 200) {
                        formRef.value?.resetFields()
                        pageData.showAdd = false
                        Message.success({
                          content: '修改成功',
                          duration: 5000,
                        })
                      } else {
                        Message.error({
                          content: res.message,
                          duration: 5000,
                        })
                      }
                    })
                    .finally(() => {
                      doRefresh()
                      pageData.pageLoading = false
                    })
                }
              }
            })
          }
        })
      }
      const deleteHandler = () => {
        if (gridOption.value.getSelectedRows().length === 0) {
          Message.error('请先勾选')
          return
        }

        Modal.confirm({
          title: '系统提示',
          content: '确认删除选中的数据?',
          onOk() {
            pageData.pageLoading = true
            post({
              url: 'product/Brand/deleteList',
              data: gridOption.value.getSelectedRows().map((o: any) => {
                return o.id
              }),
            })
              .then(({ code, data }: any) => {
                if (code === 200) {
                  Message.success({
                    content: '删除成功',
                    duration: 5000,
                  })
                  pagination.page = 1
                  doRefresh()
                } else {
                  Message.error({
                    content: '删除失败',
                    duration: 5000,
                  })
                }
              })
              .finally(() => {
                pageData.pageLoading = false
              })
          },
        })
      }

      let curobj = null
      const editHandler = (record: BrandInfo) => {
        curobj = record
        selCxAll({ key: '' })
        dataForm.brandCode = record.brandCode
        dataForm.brandName = record.brandName
        dataForm.clothClass = record.clothClass
        dataForm.remark = record.remark
        dataForm.id = record.id
        pageData.sideTitle = '修改品牌资料'
        pageData.showAdd = true
      }
      //判断是否填写了中文
      const isChiese = (value: string, cb: Function) => {
        return new Promise<void>((resolve) => {
          if (window.encodeURI(value).indexOf('%') !== -1) {
            cb('填写的值不能包含中文！')
          }
          resolve()
        })
      }
      //input离开焦点 将小写转大写
      const inputBlur = () => {
        dataForm.brandCode = dataForm.brandCode.toUpperCase()
      }
      const exportsSelectedRows = () => {
        if (gridOption.value.getSelectedRows().length > 0) {
          exports(gridOption.value.getSelectedRows())
        } else {
          Message.error('请先勾选')
          return
        }
      }

      const exportsAll = () => {
        if (pageData.firmId == '' || pageData.firmId == null) {
          Message.error('工厂必填！')
          return
        }
        if (pageData.warehouseId == '' || pageData.firmId == null) {
          Message.error('仓库必填！')
          return
        }
        post({
          url: '/wms/yarnStockRecord/getYarnStockRecord',
          data: {
            firmId: pageData.firmId,
            warehouseId: pageData.warehouseId,
            // recordDate: pageData.jianyanriqi,//记录日期
            customName: pageData.kehumingcheng, //客户
            yarnCode: pageData.yuanliaobianhao, //原料编号
            yarnName: pageData.yuanliaomingcheng, //纱线名称
            yarnBrand: pageData.yarnBrand, //纱牌
            productionBatch: pageData.pici, //生产批号-纱批
            level: pageData.level, //等级
          },
        }).then((res) => {
          if (res.data.length > 0) {
            exports(res.data)
          } else {
            Message.info('当前条件没有查询到对应的数据！')
          }
        })
      }

      //导出当日结存
      const exportsToday = ()=>{
        post({
          url: '/wms/yarnStockRecord/getYarnStockRecord',
          data: {
            firmId: pageData.firmId,
            warehouseId: pageData.warehouseId,
            // recordDate: pageData.jianyanriqi,//记录日期
            customName: pageData.kehumingcheng, //客户
            yarnCode: pageData.yuanliaobianhao, //原料编号
            yarnName: pageData.yuanliaomingcheng, //纱线名称
            yarnBrand: pageData.yarnBrand, //纱牌
            productionBatch: pageData.pici, //生产批号-纱批
            level: pageData.level, //等级
          },
        }).then((res) => {
          if (res.data.length > 0) {
            today(res.data)
          } else {
            Message.info('当前条件没有查询到对应的数据！')
          }
        })
      }

      //导出
      const exports = (rows:any) => {
        let head =
          '<tr><th colspan="12"></th><th colspan="6">上期结存</th><th colspan="6">入仓</th><th colspan="6">出仓领料</th><th colspan="6">出仓委外</th><th colspan="6">出仓其他</th><th colspan="6">本期存结</th> </tr>'
        head +=
          '<tr><th>公司</th><th>客户名称</th><th>原料编号</th><th>纱线名称</th><th>纱牌</th><th>纱批</th><th>等级</th><th>色号</th><th>色称</th><th>单位</th><th>整件/件重</th><th>上期结存</th><th>整件/件数</th><th>整件/个数</th><th>散件/件数</th><th>散件/散重</th><th>散件/个数</th><th>总数量</th><th>整件/件数</th><th>整件/个数</th><th>散件/件数</th><th>散件/散重</th><th>散件/个数</th><th>总数量</th><th>整件/件数</th><th>整件/个数</th><th>散件/件数</th><th>散件/散重</th><th>散件/个数</th><th>总数量</th><th>整件/件数</th><th>整件/个数</th><th>散件/件数</th><th>散件/散重</th><th>散件/个数</th><th>总数量</th><th>整件/件数</th><th>整件/个数</th><th>散件/件数</th><th>散件/散重</th><th>散件/个数</th><th>总数量</th><th>整件/件数</th><th>整件/个数</th><th>散件/件数</th><th>散件/散重</th><th>散件/个数</th><th>总数量</th></tr>'
        let body = ''
        rows.forEach((row:any) => {
          body += '<tr>'
          body +=
            '<td>' +
            row.firm +
            '</td><td>' +
            row.customName +
            '</td><td>' +
            row.yarnCode +
            '</td><td>' +
            row.yarnName +
            '</td><td>' +
            row.yarnBrand +
            '</td><td>' +
            row.productionBatch +
            '</td><td>' +
            row.level +
            '</td><td>' +
            row.colorCode +
            '</td><td>' +
            row.colorName +
            '</td><td>' +
            row.unit +
            '</td><td>' +
            row.pieceWeight +
            '</td><td>' +
            row.pieceWeight +
            '</td><td>' +
            row.pieceNumberBalanceL +
            '</td><td>' +
            row.pieceCountBalanceL +
            '</td><td>' +
            row.bulkNumberBalanceL +
            '</td><td>' +
            row.bulkWeightBalanceL +
            '</td><td>' +
            row.bulkCountBalanceL +
            '</td><td>' +
            row.weightTotalBalanceL +
            '</td><td>' +
            row.pieceNumberIn +
            '</td><td>' +
            row.pieceCountIn +
            '</td><td>' +
            row.bulkNumberIn +
            '</td><td>' +
            row.bulkWeightIn +
            '</td><td>' +
            row.bulkCountIn +
            '</td><td>' +
            row.weightTotalIn +
            '</td><td>' +
            row.pieceNumberOutClaim +
            '</td><td>' +
            row.pieceCountOutClaim +
            '</td><td>' +
            row.bulkNumberOutClaim +
            '</td><td>' +
            row.bulkWeightOutClaim +
            '</td><td>' +
            row.bulkCountOutClaim +
            '</td><td>' +
            row.weightTotalOutClaim +
            '</td><td>' +
            row.pieceNumberOutSource +
            '</td><td>' +
            row.pieceCountOutSource +
            '</td><td>' +
            row.bulkNumberOutSource +
            '</td><td>' +
            row.bulkWeightOutSource +
            '</td><td>' +
            row.bulkCountOutSource +
            '</td><td>' +
            row.weightTotalOutSource +
            '</td><td>' +
            row.pieceNumberOutOther +
            '</td><td>' +
            row.pieceCountOutOther +
            '</td><td>' +
            row.bulkNumberOutOther +
            '</td><td>' +
            row.bulkWeightOutOther +
            '</td><td>' +
            row.bulkCountOutOther +
            '</td><td>' +
            row.weightTotalOutOther +
            '</td><td>' +
            row.pieceNumberBalanceN +
            '</td><td>' +
            row.pieceCountBalanceN +
            '</td><td>' +
            row.bulkNumberBalanceN +
            '</td><td>' +
            row.bulkWeightBalanceN +
            '</td><td>' +
            row.bulkCountBalanceN +
            '</td><td>' +
            row.weightTotalBalanceN +
            '</td>'

          body += '</tr>'
        })
        tableToXlsx(head, '原料进存销', body)
      }

const today = (rows:any)=>{
 let head =
          '<th>客户名称</th><th>纱线名称</th><th>纱牌</th><th>纱批</th><th>色号</th><th>色称</th><th>本期结存数量</th><th>整件/件数</th><th>散件/件数</th>'
        let body = ''
        rows.forEach((row:any) => {
          body +=
            '<tr><td>' +
            row.customName +
            '</td><td>' +
            row.yarnName +
            '</td><td>' +
            row.yarnBrand +
            '</td><td>' +
            row.productionBatch +
            '</td><td>' +
            row.colorCode +
            '</td><td>' +
            row.colorName +
            '</td><td>' +
            row.weightTotalBalanceN +
            '</td><td>' +
            row.pieceNumberBalanceN +
            '</td><td>' +
            row.bulkNumberBalanceN +
            '</td>'
          body += '</tr>'
})
tableToXlsx(head, '原料进销存日报表', body)
}
      

      function tableToXlsx(head: any, filename: any, body: any) {
        const uri = 'data:application/vnd.ms-excel;base64,',
          template = `<html>
            <head><meta charset="UTF-8"></head>
            <body><table border="1">${head}${body}</table></body>
        </html>`

        const a = document.createElement('a')
        a.style.display = 'none'
        a.href = uri + window.btoa(unescape(encodeURIComponent(template)))
        a.download = filename
        document.body.appendChild(a)
        a.click()
        URL.revokeObjectURL(a.href)
        document.body.removeChild(a)
      }

      //模板下载
      const downloadHandler = () => {
        axios
          .get(baseURL + '/product/Brand/uploadModel', {
            responseType: 'blob',
            headers: {
              token: sessionStorage.getItem('USER-TOKEN-KEY'),
            },
          })
          .then((res) => {
            if (res.status === 200) {
              filedownload(res.data, '品牌资料.xlsx')
            }
          })
      }
      //导入
      const importHandler = () => {
        const inputEle: HTMLInputElement = document.createElement('input')
        inputEle.type = 'file'
        inputEle.id = 'fileUploadExcel'
        inputEle.accept =
          'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel'
        inputEle.addEventListener('change', (e) => {
          const formData = new FormData()
          if (inputEle.files !== null) {
            formData.append('file', inputEle.files[0] || '')
          } else {
            Message.warning('未选择文件！')
            return
          }
          pageData.pageLoading = true
          axios
            .post(baseURL + '/product/Brand/importModelData', formData, {
              headers: {
                'Content-Type': 'multipart/form-data',
                token: sessionStorage.getItem('USER-TOKEN-KEY'),
              },
            })
            .then((result) => {
              if (result.data['code'] === 200) {
                Message.success('导入成功')
              } else {
                Message.error(result.data.message)
              }
            })
            .finally(() => {
              pageData.pageLoading = false
              doRefresh()
            })
        })
        inputEle.click()
      }
      //下拉数据
      const options = ref<any>(pageData.pibubianhaolist)
      const loading = ref(false)
      const handleSearch1 = (value: any) => {
        if (value) {
          const ob = { greyCode: value }
          loading.value = true

          selCxAll(ob)
          options.value = pageData.pibubianhaolist
          loading.value = false
        } else {
          options.value = []
        }
      }

      //下拉框查询 布料类型
      //下拉框查询 坯布编号
      function selCxAll(val: any) {
        post({
          url: 'product/Rawmaterial/getGreyDrop',
          data: val,
        }).then(({ data, code }: any) => {
          if (code === 200) {
            // (data as string[]).splice(0, 0, "全部");
            pageData.pibubianhaolist = data
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
      }

      const options2 = ref<any>(pageData.pibumingchenglist)
      const loading2 = ref(false)
      const handleSearch2 = (value: any) => {
        if (value) {
          const ob = { grayFabricName: value }
          loading.value = true

          selCxAll2(ob)
          options.value = pageData.pibumingchenglist
          loading.value = false
        } else {
          options.value = []
        }
      }
      //下拉框查询 坯布名称
      function selCxAll2(val: any) {
        post({
          url: 'product/Rawmaterial/getGreyDrop',
          data: val,
        }).then(({ data, code }: any) => {
          if (code === 200) {
            // (data as string[]).splice(0, 0, "全部");
            pageData.pibumingchenglist = data
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
      }
      const options3 = ref<any>(pageData.kehumingchenglist)
      const loading3 = ref(false)
      const handleSearch3 = (value: any) => {
        if (value) {
          const ob = { customName: value }
          loading.value = true

          selCxAll3(ob)
          options.value = pageData.kehumingchenglist
          loading.value = false
        } else {
          options.value = []
        }
      }
      function selCxAll3(val: any) {
        post({
          url: 'planSingle/planOrder/getDropInfo',
          data: val,
        }).then(({ data, code }: any) => {
          if (code === 200) {
            // (data as string[]).splice(0, 0, "全部");
            //sessionStorage.setItem("kehumingccheng",JSON.stringify(data))
            //sessionStorage.setItem("iskehupp",JSON.stringify(data))

            pageData.kehumingchenglist = data
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
      }

      const options4 = ref<any>(pageData.jitaihaolist)
      const loading4 = ref(false)
      const handleSearch4 = (value: any) => {
        if (value) {
          const ob = { machineCode: value }
          loading.value = true

          selCxAll4(ob)
          options.value = pageData.jitaihaolist
          loading.value = false
        } else {
          options.value = []
        }
      }
      //下拉框查询 坯布名称
      function selCxAll4(val: any) {
        post({
          url: 'planSingle/machine/getFieldValue',
          data: val,
        }).then(({ data, code }: any) => {
          if (code === 200) {
            // (data as string[]).splice(0, 0, "全部");

            pageData.jitaihaolist = data
            //sessionStorage.setItem("kehumingccheng",JSON.stringify(pageData.jitaihao))
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
      }

      function selCxAll5(val: any) {
        pageData.yuanliaobianhaolist = []
        pageData.biaoji = 1
        post({
          url: '/wms/warehouseType/getWarehoursTypePara',
          data: val,
        }).then(({ data, code }: any) => {
          if (code === 200) {
            data.forEach((o: any) => {
              var obj = { label: o.typeName, value: o.id, children: [] }
              pageData.yuanliaobianhaolist.push(obj)
            })
            pageData.yuanliaobianhaolist.forEach((d) => {
              // gongsi(d)
            })
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
      }

      function selCxAll6(val: any) {
        pageData.biaoji = 2
        pageData.yuanliaomingchenglist = []
        post({
          url: '/wms/warehouseType/getWarehoursTypePara',
          data: val,
        }).then(({ data, code }: any) => {
          if (code === 200) {
            data.forEach((o: any) => {
              var obj = { label: o.typeName, value: o.id, children: [] }
              pageData.yuanliaomingchenglist.push(obj)
            })

            pageData.yuanliaomingchenglist.forEach((d) => {
              // gongsi(d)
            })
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
      }
      function selCxAll7(val: any) {
        pageData.biaoji = 3
        pageData.picilist = []
        post({
          url: '/wms/warehouseType/getWarehoursTypePara',
          data: val,
        }).then(({ data, code }: any) => {
          if (code === 200) {
            data.forEach((o: any) => {
              var obj = { label: o.typeName, value: o.id, children: [] }
              pageData.picilist.push(obj)
            })

            pageData.picilist.forEach((d) => {
              // gongsi(d)
            })
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
      }
      function getcangku(val: any) {
        post({
          url: '/wms/warehouse/getWarehouseByPara',
          data: { firmId: val.value, warehouseTypeName: val.warehouseTypeName, virtuallyState: 0 },
        }).then(({ data, code }: any) => {
          if (code === 200) {
            data.map((d: any) => {
              val.children.push({
                label: d.warehouseName,
                value: d.id,
                firmId: d.firmId,
                warehouseTypeName: d.warehouseTypeName,
                children: [],
              })
            })
            sessionStorage.setItem('abcd', JSON.stringify(pageData.yuanliaobianhaolist))
            val.children.map((a: any) => {
              getyuanliaobianhao(a)
            })
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
      }

      //获取原料编号
      function getyuanliaobianhao(val: any) {
        sessionStorage.setItem('abcdefg', JSON.stringify(val))
        post({
          url: 'wms/WarehousetypeFieldvalue/getStockByPage',
          data: {
            page: 1,
            size: 1000000000,
            warehouseTypeName: val.warehouseTypeName,
            warehouseName: val.label,
            firmId: val.firmId,
            infoType: 0,
          },
        }).then(({ data, code }: any) => {
          if (code === 200) {
            if (pageData.biaoji == 1) {
              data.list.forEach((d: any) => {
                val.children.push({ label: d.rawMaterialCode, value: d.rawMaterialCode })
              })
              val.children = val.children.filter(
                (item: any, index: any) => val.children.indexOf(item.label) === index
              )
            } else if (pageData.biaoji == 2) {
              data.list.forEach((d: any) => {
                val.children.push({ label: d.rawMaterialName, value: d.rawMaterialName })
              })
            } else if (pageData.biaoji == 3) {
              data.list.forEach((d: any) => {
                val.children.push({ label: d.batch, value: d.batch })
              })
            }
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
      }

      //下拉框得到焦点
      const focusSel1 = () => {
        selCxAll({ greyCode: '' })
      }
      const focusSel2 = () => {
        selCxAll2({ grayFabricName: '' })
      }

      const focusSel3 = () => {
        selCxAll3({ customName: '' })
      }
      const focusSel4 = () => {
        selCxAll4({ machineCode: '' })
      }
      const focusSel = () => {
        selCxAll5({})
      }
      const focusSel6 = () => {
        selCxAll6({})
      }
      const focusSel7 = () => {
        selCxAll7({})
      }
      //设置权限
      const permissionStore = usePermission()
      pageData.btnList.push('查询')
      pageData.btnList.push('导出')
      pageData.btnList.push('全部导出')
      pageData.btnList.push('导出当日结存')
      if (permissionStore.hasPermisson('ppzl.xg')) {
        pageData.isEdit = true
      }
      const handleChange = (_data: any) => {
        table.handleSuccess(_data)
      }
      const fhzy = () => {
        emit('takebiaoji', 0)
      }
      //获得公司部门组下的员工
      const getFirmGroup = () => {
        get({
          url: '/org/firmGroup/getTreeFirmGroup',
        }).then(({ code, data }) => {
          if (code === 200) {
            pageData.firmList2 = data
            huoquyuangong()
          }
        })
      }
      const huoquyuangong = () => {
        pageData.firmList2.forEach((o: any) => {
          o.children.forEach((d: any) => {
            d.children.forEach((a: any) => {
              post({
                url: 'org/employee/getList',
                data: {
                  groupId: a.value,
                  empName: '',
                },
              }).then((res) => {
                if (res.code == 200) {
                  res.data.forEach((m: any) => {
                    a.children = [{ label: m.empName, value: m.empName }]
                  })
                } else {
                  Message.error({
                    content: '查询员工名称失败',
                    duration: 5000,
                  })
                }
              })
            })
          })
        })
      }
      const defaultColDef = {
        sortable: true,
        resizable: true,
        filter: true,
        // flex: 1
      }
      const huiche = () => {
        doRefresh()
      }
      const pagingList1: any = ref(pagingList)
      const localeText1: any = ref(localeText)
      const configaggrid = {
        fileName: 'Rawmaterialstorage',
        column: tc1,
      }
      let colState = ref('')
      const { saveGridState: saveGridState01, updateGridState: updateGridState01 } =
        saveOrUpdateGridState01(configaggrid.fileName, gridOption, colState, configaggrid.column)
      const onColumnMoved = () => {
        console.log(gridOption.value)

        // saveGridState01()
      }
      const onColumnResized = () => {
        // saveGridState01()
      }
      const onColumnVisible = () => {
        // saveGridState01()
      }

      const FilterChangeds = (params: any) => {
      let data: any = {
        data: []
      }
      params.api.forEachNodeAfterFilter((row: any) => {
        data.data.push(row.data)
      })
      setTableTotalRow(gridOption, data.data, [
                'pieceNumberBalanceL',
                'bulkNumberBalanceL',
                'bulkWeightBalanceL',
                'weightTotalBalanceL',
                'pieceNumberIn',
                'bulkNumberIn',
                'bulkWeightIn',
                'weightTotalIn',
                'pieceNumberOutClaim',
                'bulkNumberOutClaim',
                'bulkWeightOutClaim',
                'weightTotalOutClaim',
                'pieceNumberOutSource',
                'bulkNumberOutSource',
                'bulkWeightOutSource',
                'weightTotalOutSource',
                'pieceNumberOutOther',
                'bulkNumberOutOther',
                'bulkWeightOutOther',
                'weightTotalOutOther',
                'pieceNumberBalanceN',
                'bulkNumberBalanceN',
                'bulkWeightBalanceN',
                'weightTotalBalanceN',
              ])
      }
      return {
        FilterChangeds,
        toFixedNum,
        onColumnMoved,
        onColumnResized,
        onColumnVisible,
        pagingList1,
        huiche,
        localeText1,
        defaultColDef,
        // tc,
        total,
        PageSize,
        change1,
        page,
        size,
        editHandler,
        deleteHandler,
        sideOk,
        formRef,
        dataForm,
        addHandler,
        selectedRowKeys,
        pagination,
        // tableColumns,
        table,
        rowKey,
        pageData,
        queryData,
        selectHandler,
        isChiese,
        inputBlur,
        exports,
        options,
        options2,
        options3,
        options4,
        loading,
        loading2,
        loading3,
        loading4,
        handleSearch1,
        handleSearch2,
        handleSearch3,
        handleSearch4,
        focusSel,
        downloadHandler,
        importHandler,
        focusSel1,
        focusSel2,
        focusSel3,
        focusSel4,
        focusSel6,
        focusSel7,
        headerShow,
        handleChange,
        gridReady,
        fhzy,
        selCxAll,
        getFirmGroup,
        configCascader2,
        fhWhList,
        firmChange,
        tc1,
        exportsSelectedRows,
        exportsAll,
        exportsToday
      }
    },
    props: {
      biaoji: Number,
    },
    components: { Toolbar, PageTabelLayout, CorporateSectorCascader },
  }
</script>
<style scoped>
  :deep(.ag-cell-value) {
    user-select: initial;
    -moz-user-select: text;
    -ms-user-select: text;
    -webkit-user-select: text;
  }

  :deep(.ag-cell) {
    border-right: 1px solid #dde2eb;
  }

  :deep(.ag-header-cell) {
    border-right: 1px solid #dde2eb;
  }

  :deep(.arco-input-wrapper) {
    width: 300px;
  }

  :deep(.blue-header) {
    color: blue;
    font-weight: bold;
  }

  :deep(.green-header) {
    color: green;
    font-weight: bold;
  }

  :deep(.bold-cell) {
    font-weight: bold;
  }
</style>
